package com.yw.controller;


import com.yw.codeManageInfo.dto.AddCodeDTO;
import com.yw.dataAsset.dto.AddDataAssetDTO;
import com.yw.dataAsset.dto.DataAssetDTO;
import com.yw.piliangDTO.StatusDTO;
import com.yw.result.PageDTO;
import com.yw.result.R;
import com.yw.service.DataAssetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@Tag(name = "数据资产管理",description = "数据资产管理")
@RequestMapping("/dataAsset")
public class DataAssetController {
    @Resource
    private DataAssetService dataAssetService;

    @Operation(summary = "条件分页查询所有数据资产管理",description = "条件分页查询所有码表")
    @PostMapping("/pageAllByQuery")
    public R pageAllByQuery(@RequestBody DataAssetDTO dataAssetDTO){
        return  R.OK(dataAssetService.pageAllByQuery(dataAssetDTO));
    }

    @Operation(summary = "根据中文名或者英文名显示详情",description = "根据中文名或者英文名显示详情")
    @PostMapping("/onclickName")
    public R onclickName(Integer id){
        return  R.OK(dataAssetService.onclickName(id));
    }

    @Operation(summary = "添加资产目录",description = "添加资产目录")
    @PostMapping("/addDataAsset")
    public R addDataAsset(@RequestBody AddDataAssetDTO addDataAssetDTO){
        return  R.OK(dataAssetService.addDataAsset(addDataAssetDTO));
    }

    //    批量发布停用
    @Operation(summary = "批量发布停用")
    @PostMapping("/batch")
    public R batch(@RequestBody StatusDTO statusDTO){
        return dataAssetService.batch(statusDTO)?R.OK("批量发布成功"):R.FAIL("批量发布失败");
    }

    //    删除
    @Operation(summary = "删除")
    @PostMapping("/deleteAsset")
    public R deleteAsset(Integer id){
        return dataAssetService.removeById(id)?R.OK():R.FAIL();
    }

    //修改单挑状态
    @Operation(summary = "修改接口状态")
    @PostMapping("/updateStatic")
    public R updateStatic(Integer id){
        return dataAssetService.updateStatic(id)?R.OK():R.FAIL();
    }

    //回显
    @Operation(summary = "编辑回显")
    @PostMapping("/update")
    public R update(Integer id){
        return R.OK(dataAssetService.getOne(id));
    }

    @Operation(summary = "修改一条数据",description = "修改一条数据")
    @PostMapping("/updateCode")
    public R updateCode(@RequestParam Integer id, @RequestBody AddDataAssetDTO addDataAssetDTO){
        return dataAssetService.updateDataAsset(id,addDataAssetDTO)?R.OK():R.FAIL();
    }

}
